$(function () {
    $(window).on('resize',function () {
        var screenWidth = $(window).innerWidth();
        //当屏幕小于997时，首页轮播图宽度100%
        if (screenWidth < 997){
            $('.mmvtc-swiper-container').parent().removeClass('container');
        }else {
            $('.mmvtc-swiper-container').parent().addClass('container');
        }
    }).trigger('resize');
    // 轮播图控制器
    var carouselSwiper = new Swiper('.mmvtc-swiper-container .swiper-container', {
        slidesPerView: 1,
        loop: true,
        grabCursor: true,
        preloadImages: false,
        watchSlidesVisibility: true,
        lazy: {
            loadPrevNext: true,
        },
        autoplay: {
            delay: 2500,
            disableOnInteraction: false,
        },
        pagination: {
            el: '.mmvtc-swiper-container .swiper-pagination',
            clickable: true,
        },
        navigation: {
            nextEl: '.mmvtc-swiper-container .icon-arrows-right',
            prevEl: '.mmvtc-swiper-container .icon-arrows-left',
        },
    });
    //鼠标进入，轮播图停止
    carouselSwiper.el.onmouseover = function () {
        carouselSwiper.autoplay.stop();
    }
    //鼠标离开，轮播图开始自动轮播
    carouselSwiper.el.onmouseleave = function () {
        carouselSwiper.autoplay.start();
    }

// 图片新闻控制器
    var picNewsSwiper = new Swiper('.pic-news-container .swiper-container', {
        direction: 'vertical',
        slidesPerView: 1,
        loop: true,
        speed: 700,
        grabCursor: true,
        watchSlidesProgress: true,
        zoom: true,
        // mousewheel: true,
        roundLengths: true,
        preloadImages: false,
        autoplay: {
            delay: 3000,
            disableOnInteraction: false,
        },
        pagination: {
            el: '.pic-news-container .swiper-pagination',
            clickable: true,
            renderBullet: function (index, className) {
                return '<span class="' + className + '">' + (index + 1) + '</span>';
            },
        },
    });
    $(".news-title .switch-direction").on('click', function () {
        var direction = $(this).data("direction");
        if (direction == "vertical") {
            $(this).data("direction", "horizontal");
            //禁止鼠标控制
            picNewsSwiper.mousewheel.disable();
            picNewsSwiper.update(true);
            $(this).text("垂直滑动")
        } else if (direction == "horizontal") {
            $(this).data("direction", "vertical");
            //开启鼠标控制
            picNewsSwiper.mousewheel.enable()
            $(this).text("水平滑动");
            picNewsSwiper.update(true);
        }
        picNewsSwiper.changeDirection();
    });
    //专业设置切换控制
    $('.nav-tabs a').click(function (e) {
        e.preventDefault()
        $(this).tab('show')
    });
    // 教师风采
    var galleryThumbsSlide = '';
    var galleryTopSlide = '';
    for (var i = 1; i <= 30; i++) {
        galleryThumbsSlide += '<div class="swiper-slide"><img src="./images/teacherStyle/t' + i + '.jpg" alt=""></div>';
        // galleryTopSlide += '<div class="swiper-slide" style="background-image:url(./images/teacherStyle/' + i + '.jpg)"></div>';
        galleryTopSlide += '<div class="swiper-slide"><div class="swiper-zoom-container"><img src="./images/teacherStyle/' + i + '.jpg" alt=""></div></div>';
    }
    $('.teacher-style-loop .gallery-thumbs .swiper-wrapper').html(galleryThumbsSlide);
    $('.teacher-style-loop .gallery-top .swiper-wrapper').html(galleryTopSlide);
    var galleryThumbs = new Swiper('.teacher-style-loop .gallery-thumbs', {
        spaceBetween: 5,
        slidesPerView: 12,
        loop:true,
        grabCursor: true,
        freeMode: true,
        speed: 8000,
        autoplay: {
            delay: 0,
            disableOnInteraction: false //就算触摸了也继续滚动
        },
        loopedSlides: $('.teacher-style-loop .gallery-thumbs .swiper-wrapper .swiper-slide').length, //looped slides should be the same
        watchSlidesVisibility: true,
        watchSlidesProgress: true,
        breakpoints:{
            1200:{
                slidesPerView: 10
            },
            994:{
                slidesPerView: 8
            },
            705:{
                slidesPerView: 7
            },
            620:{
                slidesPerView: 6
            },
            540:{
                slidesPerView: 5.5
            },
            388:{
                slidesPerView:4.5
            },
            330:{
                slidesPerView:3.5
            }
        }
    });
    var galleryTop = new Swiper('.teacher-style-loop .gallery-top', {
        spaceBetween: 10,
        loop: true,
        grabCursor: true,
        effect: 'fade',
        autoplay: {
            delay: 5500,
            disableOnInteraction: false //就算触摸了也继续滚动
        },
        loopedSlides: $('.teacher-style-loop .gallery-top .swiper-wrapper .swiper-slide').length, //looped slides should be the same
        navigation: {
            nextEl: '.icon-arrows-right',
            prevEl: '.icon-arrows-left',
        },
        thumbs: {
            swiper: galleryThumbs,
        },
    });
    //鼠标进入，轮播图停止
    galleryTop.el.onmouseover = function () {
        galleryTop.autoplay.stop();
    }
    //鼠标离开，轮播图开始自动轮播
    galleryTop.el.onmouseleave = function () {
        galleryTop.autoplay.start();
    }

});